package com.fenghongzhang.day012;

import androidx.appcompat.app.AppCompatActivity;
import androidx.localbroadcastmanager.content.LocalBroadcastManager;

import android.content.Intent;
import android.content.IntentFilter;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;

public class Main2Activity extends AppCompatActivity {
    private Button btn;

    private LocalBroadcastManager instance;
    private MyReceiver4 myReceiver4;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main2);


        btn = (Button) findViewById(R.id.btn);
        instance = LocalBroadcastManager.getInstance(this);

         myReceiver4 = new MyReceiver4();
        IntentFilter intentFilter = new IntentFilter();
        intentFilter.addAction("com.feng");
        instance.registerReceiver(myReceiver4,intentFilter);


        btn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                Intent intent = new Intent();
                intent.setAction("com.feng");
                instance.sendBroadcast(intent);
            }
        });

    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        instance.unregisterReceiver(myReceiver4);
    }
}
